home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / btxmac.tex < prev    next >
Text File  |  1992-03-03  |  33KB  |  832 lines

  1. %% @texfile{
  2. %%   author = "Karl Berry and Oren Patashnik",
  3. %%   version = "0.99i,
  4. %%   date = "29 Feb 1992",
  5. %%   filename = "btxmac.tex",
  6. %%   address = "Please use electronic mail",
  7. %%   checksum = "831    4478   32900",
  8. %%   email = "opbibtex@cs.stanford.edu",
  9. %%   codetable = "ISO/ASCII",
  10. %%   supported = "yes",
  11. %%   docstring = "Defines macros that make BibTeX work with plain TeX",
  12. %% }
  13. % BibTeX-for-TeX macros, version 0.99i, for BibTeX 0.99c, TeX 3.0 or later.
  14. % Copyright (C) 1990--92 by Karl Berry and Oren Patashnik; all rights reserved.
  15. % You may copy this file provided: that it's accompanied by the
  16. % "BibTeXing" document, whose text is contained in the file `btxdoc.tex';
  17. % that any documentation you write for these macros also gives a
  18. % reference for "BibTeXing"; and that either you make absolutely no
  19. % changes to your copy, or if you do make changes, (1) you name the file
  20. % something other than `btxmac.tex' and you remove all occurrences of
  21. % `btxmac.tex' from the file, (2) you put, somewhere in the first twenty
  22. % lines of the file, your name, along with an electronic address at which
  23. % others who might use the file may reach you, and (3) you remove each
  24. % occurrence of Oren's name and electronic address from this file.  These
  25. % restrictions help ensure that all standard versions of these macros are
  26. % identical, and that Oren doesn't get deluged with inappropriate e-mail.
  27. %
  28. % This file, btxmac.tex, contains TeX macros that allow BibTeX, a
  29. % bibliography program that was originally designed for use with LaTeX,
  30. % to work with plain TeX.  Please report any bugs (outright goofs,
  31. % improvable macros, misfeatures, or unclear documentation) to Oren
  32. % Patashnik (opbibtex@cs.stanford.edu).  These macros will become frozen
  33. % shortly after BibTeX version 1.00 is released.
  34. %
  35. % AMS-TEX WARNING: We tried very hard, for version .99i of these macros,
  36. % to make them compatible with AmS-TeX.  We succeeded to the extent
  37. % that, if you use one of the standard bibliography styles, you probably
  38. % won't notice any problems with version 0.99i of btxmac.tex.  But
  39. % ultimately we failed, in that the inherent incompatibilities between
  40. % plain TeX and AmS-TeX kept making these macros break, for certain
  41. % inputs or certain styles.  Examples:  (1) AmS-TeX treats at-signs as
  42. % special, in ways that plain TeX and LaTeX don't, so that, for example,
  43. % you can't have any `@' characters in an argument to the \cite command,
  44. % the way you can in TeX or LaTeX; (2) AmS-TeX decided that plain TeX's
  45. % and LaTeX's macron-accent control sequence `\=' should be undefined;
  46. % so you'll need to define `\=' to be `\B' to get the xampl.bib example
  47. % suggested below to work with AmS-TeX; (3) AmS-TeX redefines the tie
  48. % character `~' of plain TeX, and AmS-TeX's `amsppt' style redefines
  49. % plain TeX's `\nobreak' macro, so that if you use an author-date style
  50. % like `apalike' and you have a multiple-author reference for which the
  51. % author-date style automatically produces a citation in the text like
  52. % `(Jones et~al., 1992)' you will throw AmS-TeX's `amsppt' style into
  53. % an infinite loop, exceeding its input stack size.  In practice, such
  54. % incompatibilities surface infrequently; but it is now clear to us that
  55. % it's not worth the effort (perhaps it's not even possible) to make the
  56. % btxmac.tex macros robust when used both with plain TeX and Ams-TeX.
  57. % If the BibTeX/AmS-TeX results attainable with the current btxmac.tex
  58. % macros are sufficient, fine.  But if there's a demand for more robust
  59. % BibTeX/AmS-TeX behavior, then someone who's very familiar with the
  60. % AmS-TeX package should probably make an amsbtxmc.tex version of the
  61. % macros (remembering to follow the copyright restrictions above).
  62. % Until then, if you're an AmS-TeX user, or a LaTeX or plain TeX user
  63. % sharing files with an AmS-TeX user, beware.
  64. % END OF AMS-TEX WARNING.
  65. %
  66. % To use these macros you should be familiar with how BibTeX interacts
  67. % with LaTeX, since BibTeX's interaction with TeX is very similar; that
  68. % interaction is explained in the LaTeX manual.  It also helps to
  69. % have read "BibTeXing", the documentation that accompanies BibTeX.
  70. % Then, if you want, you should redefine any of the macros that begin
  71. % with `\bbl' or `\biblabel' or `\print' that you need to get formatting
  72. % different from the default (the default settings are designed to
  73. % accompany a bibliography style like BibTeX's standard style `plain').
  74. % The macros you might want to change are described briefly a few
  75. % paragraphs hence.  [To get started without reading any documentation,
  76. % try running the nine-line .tex file below through TeX and BibTeX.
  77. % Remember the general scheme: Running (La)TeX writes information on
  78. % the .aux (auxiliary) file; then running BibTeX reads information from
  79. % the .aux, .bst (style), and .bib (database) files, and writes
  80. % information (the bibliography) on a .bbl file; then running (La)TeX
  81. % incorporates the bibliography; then running (La)TeX once more fixes
  82. % the remaining forward references into the bibliography.  Thus, to get
  83. % everything incorporated into your output, you'll have to run (La)TeX,
  84. % BibTeX, (La)TeX, (La)TeX.  (Standup, sitdown, fight, fight, fight.)]
  85. %
  86. % These macros can stand alone or they can be \input into a macro
  87. % package, like Eplain, that is sufficiently compatible with plain TeX.
  88. % To use these macros to format the 0.99 version of the xampl.bib file
  89. % that's distributed with BibTeX (that version of the file has no
  90. % self-identification), you'll need to define \mbox, which is a LaTeX
  91. % command, to be \hbox, as in the example below.
  92. %
  93. % Here's a nine-line plain TeX file for trying out btxmac.tex; of course
  94. % you'll have to remove the comment characters at the beginning of each
  95. % line, and, depending on your system, you might have to take steps so
  96. % that BibTeX can "see" the files xampl.bib and plain.bst (BibTeX will
  97. % give you two empty-field warning messages that you should ignore).
  98. %
  99. %     \def\mbox#1{\leavevmode\hbox{#1}}
  100. %     \input btxmac
  101. %     \noindent This cites Aamport's gnominious article~\cite{article-full}.
  102. %     \medskip
  103. %     \leftline{\bf References}
  104. %     \nocite{*}   % put all database entries into the reference list
  105. %     \bibliography{xampl}   % specify the database files; here, just xampl.bib
  106. %     \bibliographystyle{plain}   % specify plain.bst as the style file
  107. %     \bye
  108. %
  109. %
  110. %   HISTORY
  111. %
  112. % Karl Berry wrote the original version of these macros in 1989 and
  113. % 1990, for use in his `Eplain' package.  Oren Patashnik modified them
  114. % slightly in July 1990, as part of the official BibTeX distribution.
  115. %
  116. %    1-Aug-90  Version 0.99a, not released to the general public.
  117. %   14-Aug-90  0.99b, first general release.
  118. %   26-Aug-90  0.99c, made \@undefinedmessage work with other macro packages.
  119. %    6-Sep-90  0.99d, allowed for general formatting of bibliography labels,
  120. %                     for general formatting of (in-text) citations, and for
  121. %                     changing certain catcodes while reading the .aux file.
  122. %   14-Nov-90  0.99e, changed the way \@setletters works, made some \new...'s
  123. %                     non-outer, and changed the way Eplain reads this file.
  124. %   12-Dec-90  0.99f, made \@resetnumerals change the `,' and `.' catcodes; and
  125. %                     added \biblabelextrahang, \@getoptionalarg, and \bblsc.
  126. %   11-Mar-91  0.99g, made a few minor changes required by the way Eplain reads
  127. %                     this file, but no functional changes.
  128. %   24-Apr-91  0.99h, inhibited the reading and writing of the .aux file if it
  129. %                     isn't used or if the \noauxfile macro is defined, and
  130. %                     removed some .aux-file-opening detritus; printed the
  131. %                     cite-key of undefined citations in \tt font; changed the
  132. %                     catcode of `_' inside \cite; and called \@resetnumerals
  133. %                     from inside a group.
  134. %   29-Feb-92  0.99i, made these macros semi-compatible with AmS-TeX; removed
  135. %                     \@resetnumerals, \@setletters, \@tokstostring, and
  136. %                     friends; changed the way \cite handles catcodes; changed
  137. %                     \@getoptionalarg, and had \bibitem and \newcommand use
  138. %                     it; added \@futurenonspacelet and (to facilitate the use
  139. %                     of multiple reference lists) \bblfilebasename; changed
  140. %                     \biblabelprint to use the new macros \biblabelprecontents
  141. %                     and \biblabelpostcontents, and to, by default, right-
  142. %                     justify numeric labels; and renamed \biblabelextrahang to
  143. %                     the more descriptive \biblabelextraspace.
  144. %
  145. %
  146. % The LaTeX-related commands defined in this file include (a) the four
  147. % commands that a user types (\bibliography, \bibliographystyle, \cite,
  148. % and \nocite); (b) the three commands that BibTeX looks for in the .aux
  149. % file (\bibdata, \bibstyle, and \citation---there is a fourth command
  150. % that BibTeX looks for, but that command is related to LaTeX's \include
  151. % facility, so these macros ignore that command); and (c) a LaTeX
  152. % command (\newcommand) that's written by one of the four standard
  153. % bibliography styles (alpha).  The definitions here are not exactly the
  154. % same as the corresponding LaTeX definitions (those eight LaTeX
  155. % definitions depend on a significant fraction of LaTeX itself).  But
  156. % the only substantial differences are with \newcommand, which here,
  157. % without complaining, lets you redefine a preexisting control sequence
  158. % (in LaTeX, \newcommand won't let you redefine a preexisting command),
  159. % and which here doesn't make the control sequences it defines \long (in
  160. % LaTeX, that happens automatically); there may also be other minor
  161. % differences.  To summarize: Unless you know what you're doing, you
  162. % shouldn't define any control sequences with these eight names:
  163. %
  164. % \bibdata
  165. % \bibliography
  166. % \bibliographystyle
  167. % \bibstyle
  168. % \citation
  169. % \cite
  170. % \newcommand
  171. % \nocite
  172. %
  173. % There are three other commands written by one or more of the four
  174. % standard (plain, abbrv, alpha, unsrt) or four semistandard (acm,
  175. % apalike, ieeetr, siam) bibliography styles; they take effect only
  176. % within the bibliography, and are redefinable, as explained later:
  177. %
  178. % \em
  179. % \newblock
  180. % \sc
  181. %
  182. % There's one control sequence you might want to use (but not redefine)
  183. % in redefining \biblabelprint:
  184. %
  185. % \biblabelwidth
  186. %
  187. % There are fifteen other control sequences (explained later in more detail)
  188. % that the macros of this file will use if you define them---you should
  189. % define them after the \input btxmac command but before the \bibliography
  190. % command.  The first six begin with `\bbl' and affect fonts, spacing,
  191. % perhaps other characteristics of the bibliography, and which .bbl files
  192. % get read; the next five begin with `\biblabel' and determine how labels
  193. % are formatted in the bibliography; and the last four begin with `\print'
  194. % and determine how the in-text citations are formatted:
  195. %
  196. % \bblem
  197. % \bblfilebasename
  198. % \bblhook
  199. % \bblnewblock
  200. % \bblrm
  201. % \bblsc
  202. % \biblabelcontents
  203. % \biblabelprecontents
  204. % \biblabelprint
  205. % \biblabelpostcontents
  206. % \biblabelextraspace
  207. % \printbetweencitations
  208. % \printcitefinish
  209. % \printcitenote
  210. % \printcitestart
  211. %
  212. % If it's defined before the \input btxmac command, the control sequence
  213. % below inhibits the reading and writing of the .aux file(s), and the
  214. % issuing of related warning messages.  Any definition will do.  This
  215. % feature might help when you're working on draft stages of a document:
  216. %
  217. % \noauxfile
  218. %
  219. %
  220. % Here's another control sequence (it's described later) that you
  221. % probably won't want to redefine unless you are writing another macro
  222. % package; if you do redefine it, however, do it before the \input btxmac
  223. % command (and notice that it has an `@' in its name):
  224. %
  225. % \@undefinedmessage
  226. %
  227. % Any other control sequence in this file that might conflict with
  228. % something you've defined will have an `@' in its name, so such conflicts
  229. % are unlikely; but if you're worried about a specific control sequence
  230. % name, do a text search of this file to look for it.
  231. %
  232. %
  233. % So to start things off we turn `@' into a letter (category code 11),
  234. % keeping track of the old category code for future restoration.
  235. % (Simply resetting it to 12 when we leave these macros is
  236. % insufficient.)  The use of `\cite' as a temporary control sequence is
  237. % a kludge, but it's a reasonably simple way to accomplish what we need
  238. % without possibly overwriting something (without an `@' in its name)
  239. % that might already be defined.
  240. %
  241. \edef\cite{\the\catcode`@}%
  242. \catcode`@ = 11
  243. \let\@oldatcatcode = \cite
  244. \chardef\@letter = 11
  245. \chardef\@other = 12
  246. %
  247. %
  248. % Next come some things that will be useful later.
  249. %
  250. % Make an outer definition into an inner one (due to Chris Thompson).
  251. % The arguments should be the control sequence to be defined, and the
  252. % new of the \outer control sequence, as characters; the control
  253. % sequence #1 is defined to be just the same as \csname#2\endcsname, but
  254. % not \outer.  For example, \@innerdef\innernewcount{newcount} would
  255. % define \innernewcount to be a non-outer version of \newcount.
  256. %
  257. \def\@innerdef#1#2{\edef#1{\expandafter\noexpand\csname #2\endcsname}}%
  258. %
  259. % We use \@innerdef to make some of our allocations local, because
  260. % Eplain includes our code inside a conditional.  We put @'s in the
  261. % names to minimize the (already small) chance of conflicts.
  262. %
  263. \@innerdef\@innernewcount{newcount}%
  264. \@innerdef\@innernewdimen{newdimen}%
  265. \@innerdef\@innernewif{newif}%
  266. \@innerdef\@innernewwrite{newwrite}%
  267. %
  268. %
  269. % Swallow one parameter.
  270. %
  271. \def\@gobble#1{}%
  272. %
  273. %
  274. % Use TeX 3.0's \inputlineno to get the line number, for better error
  275. % messages, but if we're using an old version of TeX, don't do anything.
  276. %
  277. \ifx\inputlineno\@undefined
  278.    \let\@linenumber = \empty % Pre-3.0.
  279. \else
  280.    \def\@linenumber{\the\inputlineno:\space}%
  281. \fi
  282. %
  283. %
  284. % The following macro \@futurenonspacelet (from the TeXbook) behaves
  285. % essentially like \futurelet except that it discards any implicit or
  286. % explicit space tokens that intervene before a nonspace is scanned:
  287. %
  288. \def\@futurenonspacelet#1{\def\cs{#1}%
  289.    \afterassignment\@stepone\let\@nexttoken=
  290. }%
  291. \def\\{\let\@stoken= }%
  292. \\ % now \@stoken is a space token (\\ is a control symbol, so that
  293.    % space after it is seen).
  294. \def\@stepone{\expandafter\futurelet\cs\@steptwo}%
  295. \def\@steptwo{\expandafter\ifx\cs\@stoken\let\@@next=\@stepthree
  296.    \else\let\@@next=\@nexttoken\fi \@@next}%
  297. \def\@stepthree{\afterassignment\@stepone\let\@@next= }%
  298. %
  299. %
  300. % \@getoptionalarg\CS gets an optional argument from the input, enclosed
  301. % in brackets, then expands \CS.  We set \@optionalarg to \empty if we
  302. % don't find one, otherwise to the text of the argument.  This assumes
  303. % the brackets don't have a funny category code.
  304. %
  305. \def\@getoptionalarg#1{%
  306.    \let\@optionaltemp = #1%
  307.    \let\@optionalnext = \relax
  308.    \@futurenonspacelet\@optionalnext\@bracketcheck
  309. }%
  310. %
  311. % The \expandafter's in this macro let us avoid the use of \aftergroup,
  312. % which is somewhat more expensive.
  313. %
  314. \def\@bracketcheck{%
  315.    \ifx [\@optionalnext
  316.       \expandafter\@@getoptionalarg
  317.    \else
  318.       \let\@optionalarg = \empty
  319.       % We can't do the \temp after the \fi, because then the \temp gets
  320.       % in the way of reading the optional argument from the input, if
  321.       % we do have one.
  322.       \expandafter\@optionaltemp
  323.    \fi
  324. }%
  325. %
  326. \def\@@getoptionalarg[#1]{%
  327.    \def\@optionalarg{#1}%
  328.    \@optionaltemp
  329. }%
  330. %
  331. %
  332. % From LaTeX.
  333. %
  334. \def\@nnil{\@nil}%
  335. \def\@fornoop#1\@@#2#3{}%
  336. %
  337. \def\@for#1:=#2\do#3{%
  338.    \edef\@fortmp{#2}%
  339.    \ifx\@fortmp\empty \else
  340.       \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}%
  341.    \fi
  342. }%
  343. %
  344. \def\@forloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
  345.        #5\def#4{#2}\ifx #4\@nnil \else#5\@iforloop #3\@@#4{#5}\fi\fi
  346. }%
  347. %
  348. \def\@iforloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
  349.        \let\@nextwhile=\@fornoop \else
  350.       #4\relax\let\@nextwhile=\@iforloop\fi\@nextwhile#2\@@#3{#4}%
  351. }%
  352. %
  353. %
  354. % This macro tests if a file \jobname.#1 exists, and sets \if@fileexists
  355. % appropriately.  If an optional argument is given, it is used as the
  356. % root part of the filename instead of \jobname.
  357. %
  358. \@innernewif\if@fileexists
  359. %
  360. \def\@testfileexistence{\@getoptionalarg\@finishtestfileexistence}%
  361. \def\@finishtestfileexistence#1{%
  362.    \begingroup
  363.       \def\extension{#1}%
  364.       \immediate\openin0 =
  365.          \ifx\@optionalarg\empty\jobname\else\@optionalarg\fi
  366.          \ifx\extension\empty \else .#1\fi
  367.          \space
  368.       \ifeof 0
  369.          \global\@fileexistsfalse
  370.       \else
  371.          \global\@fileexiststrue
  372.       \fi
  373.       \immediate\closein0
  374.    \endgroup
  375. }%
  376. %
  377. %
  378. %% [[[start of BibTeX-specific stuff]]]
  379. %
  380. % Now come the four main LaTeX commands and their associated .aux
  381. % commands.  Just as in LaTeX, \bibliographystyle defines the BibTeX
  382. % style name (.bst file, that is), and \bibliography defines the
  383. % database (.bib) file(s).  The corresponding .aux-file commands are
  384. % \bibstyle and \bibdata, which are there only for BibTeX's (but not
  385. % LaTeX's) use.
  386. %
  387. \def\bibliographystyle#1{%
  388.    \@readauxfile
  389.    \@writeaux{\string\bibstyle{#1}}%
  390. }%
  391. \let\bibstyle = \@gobble
  392. %
  393. % As well as writing the \bibdata command to tell BibTeX which .bib
  394. % files to read, we read the .bbl file that BibTeX (or a person,
  395. % conceivably) has produced.  We use \bblfilebasename as the root of the
  396. % filename to read; this defaults to \jobname.
  397. %
  398. \let\bblfilebasename = \jobname
  399. \def\bibliography#1{%
  400.    \@readauxfile
  401.    \@writeaux{\string\bibdata{#1}}%
  402.    \@testfileexistence[\bblfilebasename]{bbl}%
  403.    \if@fileexists
  404.       % We just output a non-discardable item (the `whatsit' with the
  405.       % \bibdata command).  This means that the glue that will be
  406.       % inserted next (\parskip or \baselineskip, most likely) will be a
  407.       % legal breakpoint.  Most likely, this is after some kind of
  408.       % heading, where we don't want to allow a page break.  So:
  409.       \nobreak
  410.       \@readbblfile
  411.    \fi
  412. }%
  413. \let\bibdata = \@gobble
  414. %
  415. % The \nocite{label,label,...} command writes its argument to \@auxfile,
  416. % unless instructed not to, but produces no text in the document.  Both
  417. % the \nocite and \cite commands produce \citation commands in the .aux file.
  418. %
  419. \def\nocite#1{%
  420.    \@readauxfile
  421.    \@writeaux{\string\citation{#1}}%
  422. }%
  423. %
  424. \@innernewif\if@notfirstcitation
  425. %
  426. % \cite[note]{label,label,...} produces the citations for the labels as
  427. % well.  If the optional argument `note' is present, it's added after
  428. % the labels.  Since \cite calls \nocite to do its .aux-file writing,
  429. % \cite doesn't need to call \@readauxfile (\nocite does).
  430. %
  431. \def\cite{\@getoptionalarg\@cite}%
  432. %
  433. % Typeset the citations for the labels in #1, followed by the note, if
  434. % it exists.  To change the citation's format in the text, redefine one
  435. % or more `\print...' macros, whose defaults appear later in this file.
  436. %
  437. \def\@cite#1{%
  438.    % Remember the optional argument, in case one of the macros we call
  439.    % below ends up looking for an optional argument itself.  For
  440.    % example, if a \cite[note] triggers reading the .aux file, then the
  441.    % [note] would be clobbered, since \@testfileexistence looks for an
  442.    % optional arg.
  443.    \let\@citenotetext = \@optionalarg
  444.    % Start printing the text, beginning with a left bracket by default.
  445.    \printcitestart
  446.    % It's complicated, but because \nocite puts a `whatsit' onto the list,
  447.    % \nocite should follow \printcitestart.  It's conceivable, but very
  448.    % unlikely, that this `whatsit' will cause a problem (glue that doesn't
  449.    % disappear when you want it to is the most likely symptom), requiring
  450.    % a change either to \printcitestart or to the label that the .bst file
  451.    % produces.
  452.    \nocite{#1}%
  453.    \@notfirstcitationfalse
  454.    \@for \@citation :=#1\do
  455.    {%
  456.       \expandafter\@onecitation\@citation\@@
  457.    }%
  458.    \ifx\empty\@citenotetext\else
  459.       \printcitenote{\@citenotetext}%
  460.    \fi
  461.    \printcitefinish
  462. }%
  463. %
  464. \def\@onecitation#1\@@{%
  465.    \if@notfirstcitation
  466.       \printbetweencitations
  467.    \fi
  468.    %
  469.    \expandafter \ifx \csname\@citelabel{#1}\endcsname \relax
  470.       \if@citewarning
  471.          \message{\@linenumber Undefined citation `#1'.}%
  472.       \fi
  473.       % Give it a dummy definition:
  474.       \expandafter\gdef\csname\@citelabel{#1}\endcsname{%
  475.          {\tt
  476.             \escapechar = -1
  477.             \nobreak\hskip0pt
  478.             \expandafter\string\csname#1\endcsname
  479.             \nobreak\hskip0pt
  480.          }%
  481.       }%
  482.    \fi
  483.    % Now produce the text, whether it was undefined or not.
  484.    \csname\@citelabel{#1}\endcsname
  485.    \@notfirstcitationtrue
  486. }%
  487. %
  488. % Given a label `foo', the macro `\b@foo' is supposed to
  489. % hold the text that should be produced.
  490. %
  491. \def\@citelabel#1{b@#1}%
  492. %
  493. % So, how does a citation label get defined?  When we read the .bbl file
  494. % (below), a \bibitem writes out a \@citedef command.  And when we read
  495. % the \@citedef, we define \@citelabel{#1}, where #1 is the user's
  496. % label.
  497. %
  498. \def\@citedef#1#2{\expandafter\gdef\csname\@citelabel{#1}\endcsname{#2}}%
  499. %
  500. %
  501. % Reading the .bbl file also produces the typeset bibliography.  Please
  502. % notice, however, that we do not produce the title for the references
  503. % (e.g., `References'), as LaTeX does.  The formatting and spacing of
  504. % that title, whether it should go into the headline, and so on, are all
  505. % things determined by your format.  We cannot know those things in
  506. % advance.  If you wish, you can define \bblhook to produce the title.
  507. % Or just do it before the \bibliography command.
  508. %
  509. \def\@readbblfile{%
  510.    % Define a counter to tell us which item number we are on, unless
  511.    % we've already defined it (because the document has more than one
  512.    % bibliography).
  513.    \ifx\@itemnum\@undefined
  514.       \@innernewcount\@itemnum
  515.    \fi
  516.    %
  517.    \begingroup
  518.       \def\begin##1##2{%
  519.          % ##1 is just `thebibliography'.
  520.          % ##2 is the widest label.
  521.          % We set (new dimen) \biblabelwidth based on the widest label
  522.          \setbox0 = \hbox{\biblabelcontents{##2}}%
  523.          \biblabelwidth = \wd0
  524.       }%
  525.       \def\end##1{}% ##1 is `thebibliography' again.
  526.       %
  527.       % Here we have two possibilities:
  528.       % \bibitem[typesetlabel]{citationlabel}
  529.       % \bibitem{citationlabel}
  530.       % If we have the second of these, the citations are numbered, starting
  531.       % from one; we use our own count register \@itemnum for this.
  532.       %
  533.       \@itemnum = 0
  534.       \def\bibitem{\@getoptionalarg\@bibitem}%
  535.       \def\@bibitem{%
  536.          \ifx\@optionalarg\empty
  537.             \expandafter\@numberedbibitem
  538.          \else
  539.             \expandafter\@alphabibitem
  540.          \fi
  541.       }%
  542.       \def\@alphabibitem##1{%
  543.          % Need \xdef here for various reasons.
  544.          \expandafter \xdef\csname\@citelabel{##1}\endcsname {\@optionalarg}%
  545.          % Left-justify alpha labels, unless \biblabel{pre,post}contents
  546.          % are already defined.
  547.          \ifx\biblabelprecontents\@undefined
  548.             \let\biblabelprecontents = \relax
  549.          \fi
  550.          \ifx\biblabelpostcontents\@undefined
  551.             \let\biblabelpostcontents = \hss
  552.          \fi
  553.          \@finishbibitem{##1}%
  554.       }%
  555.       %
  556.       \def\@numberedbibitem##1{%
  557.          \advance\@itemnum by 1
  558.          \expandafter \xdef\csname\@citelabel{##1}\endcsname{\number\@itemnum}%
  559.          % Right-justify numeric labels, unless \biblabel{pre,post}contents
  560.          % are already defined.
  561.          \ifx\biblabelprecontents\@undefined
  562.             \let\biblabelprecontents = \hss
  563.          \fi
  564.          \ifx\biblabelpostcontents\@undefined
  565.             \let\biblabelpostcontents = \relax
  566.          \fi
  567.          \@finishbibitem{##1}%
  568.       }%
  569.       %
  570.       \def\@finishbibitem##1{%
  571.          \biblabelprint{\csname\@citelabel{##1}\endcsname}%
  572.          \@writeaux{\string\@citedef{##1}{\csname\@citelabel{##1}\endcsname}}%
  573.          \ignorespaces
  574.       }%
  575.       %
  576.       % Do the printing (we're producing the bibliography, remember).
  577.       %
  578.       \let\em = \bblem
  579.       \let\newblock = \bblnewblock
  580.       \let\sc = \bblsc
  581.       % Punctuation won't affect spacing;
  582.       \frenchspacing
  583.       % the penalties below are from LaTeX's [article,book,report].sty;
  584.       \clubpenalty = 4000 \widowpenalty = 4000
  585.       % the next two values come from LaTeX's \sloppy command;
  586.       \tolerance = 10000 \hfuzz = .5pt
  587.       \everypar = {\hangindent = \biblabelwidth
  588.                       \advance\hangindent by \biblabelextraspace}%
  589.       \bblrm
  590.       % the \parskip is a guess at what looks good;
  591.       \parskip = 1.5ex plus .5ex minus .5ex
  592.       % and the space between label and text comes from LaTeX's \labelsep.
  593.       \biblabelextraspace = .5em
  594.       \bblhook
  595.       %
  596.       \input \bblfilebasename.bbl
  597.    \endgroup
  598. }%
  599. %
  600. % The widest label's width is useful for redefining \biblabelprint;
  601. % you redefine \biblabelwidth, in effect, by redefining the
  602. % \biblabelcontents macro that appears below.  And \biblabelextraspace,
  603. % which is redefinable inside \bblhook, is added to \biblabelwidth to
  604. % determine the amount of hanging indentation.
  605. %
  606. \@innernewdimen\biblabelwidth
  607. \@innernewdimen\biblabelextraspace
  608. %
  609. % Now come the main macros that are related to the printing of the
  610. % bibliography.  Since you might want to redefine them, they are given
  611. % default definitions outside of \@readbblfile.
  612. %
  613. % The first one controls the printing of a bibliography entry's label.
  614. % If you change it, make sure that it starts with something like
  615. % \noindent or \indent or \leavevmode that puts TeX into horizontal mode
  616. % (even if the label itself is empty); otherwise, the hanging
  617. % indentation will get messed up in certain circumstances.
  618. %
  619. \def\biblabelprint#1{%
  620.    \noindent
  621.    \hbox to \biblabelwidth{%
  622.       \biblabelprecontents
  623.       \biblabelcontents{#1}%
  624.       \biblabelpostcontents
  625.    }%
  626.    \kern\biblabelextraspace
  627. }%
  628. %
  629. % If you are using numeric labels, and you want them left-justified
  630. % (numeric labels by default are right-justified), do something like:
  631. %     \def\biblabelprecontents{\relax}
  632. %     \def\biblabelpostcontents{\hss}
  633. %
  634. % By default the labels are typeset in \bblrm, and enclosed in brackets.
  635. %
  636. \def\biblabelcontents#1{{\bblrm [#1]}}%
  637. %
  638. % The main text, too, is typeset using \bblrm, which is \rm by default.
  639. %
  640. \def\bblrm{\rm}%
  641. %
  642. % Emphasis for producing, e.g., titles, is done with \it by default.
  643. %
  644. \def\bblem{\it}%
  645. %
  646. % Some styles use a caps-and-small-caps font for author names.  LaTeX
  647. % defines an \sc command but plain TeX doesn't, so we need one here.
  648. % The definition below doesn't load the font unless it's needed, but it
  649. % tries to load only the 10pt version, because it might not exist at
  650. % other point sizes.
  651. %
  652. \def\bblsc{\ifx\@scfont\@undefined
  653.               \font\@scfont = cmcsc10
  654.            \fi
  655.            \@scfont
  656. }%
  657. %
  658. % The major parts of an entry are separated with \bblnewblock.  The
  659. % numbers below are taken from LaTeX's `article' style.
  660. %
  661. \def\bblnewblock{\hskip .11em plus .33em minus .07em }%
  662. %
  663. % Here's where you stick any other bibliography-formatting goodies, or
  664. % redefine the values above.
  665. %
  666. \let\bblhook = \empty
  667. %
  668. %
  669. % Here are the four default definitions for formatting the in-text
  670. % citations.  These are what you redefine (after your \input btxmac but
  671. % before your \bibliography) to get parens instead of brackets, or
  672. % superscripts, or footnotes, or whatever.
  673. %
  674. \def\printcitestart{[}%         left bracket
  675. \def\printcitefinish{]}%        right bracket
  676. \def\printbetweencitations{, }% comma, space
  677. \def\printcitenote#1{, #1}%     comma, space, note (if it exists)
  678. %
  679. % That scheme is pretty flexible.  For example you could use
  680. %     \def\printcitestart{\unskip $^\bgroup}
  681. %     \def\printcitefinish{\egroup$}
  682. %     \def\printbetweencitations{,}
  683. %     \def\printcitenote#1{\hbox{\sevenrm\space (#1)}}
  684. %     \font\eighttt = cmtt8
  685. %     \scriptfont\ttfam = \eighttt
  686. % to get superscripted in-text citations.  (The scriptfont stuff
  687. % exists only to print an undefined citation; it's in cmtt8 because
  688. % there is no cmtt7.)  To get something radically different, however,
  689. % you'll have to define your own \cite command.
  690. %
  691. % When we read `\citation' from the .aux file, it means nothing.
  692. %
  693. \let\citation = \@gobble
  694. %
  695. %
  696. % Now comes the stuff for dealing with LaTeX's \newcommand.  As
  697. % mentioned earlier, this \newcommand will redefine a preexisting
  698. % command; that's different from how LaTeX's \newcommand behaves.
  699. %
  700. \@innernewcount\@numparams
  701. %
  702. % \newcommand{\foo}[n]{text} defines the control sequence \foo to have
  703. % n parameters, and replacement text `text'.
  704. %
  705. \def\newcommand#1{%
  706.    \def\@commandname{#1}%
  707.    \@getoptionalarg\@continuenewcommand
  708. }%
  709. %
  710. % Figure out if this definition has parameters.
  711. %
  712. \def\@continuenewcommand{%
  713.    % If no optional argument, we have zero parameters.  Otherwise, we
  714.    % have that many.
  715.    \@numparams = \ifx\@optionalarg\empty 0\else\@optionalarg \fi \relax
  716.    \@newcommand
  717. }%
  718. %
  719. % \@numparams is how many arguments this command has.  The name of the
  720. % command is \@commandname.  The replacement text for the new macro is #1.
  721. %
  722. \def\@newcommand#1{%
  723.    \def\@startdef{\expandafter\edef\@commandname}%
  724.    \ifnum\@numparams=0
  725.       \let\@paramdef = \empty
  726.    \else
  727.       \ifnum\@numparams>9
  728.          \errmessage{\the\@numparams\space is too many parameters}%
  729.       \else
  730.          \ifnum\@numparams<0
  731.             \errmessage{\the\@numparams\space is too few parameters}%
  732.          \else
  733.             \edef\@paramdef{%
  734.                % This is disgusting, but \loop doesn't work inside \edef,
  735.                % because \body isn't defined.
  736.                \ifcase\@numparams
  737.                   \empty  No arguments.
  738.                \or ####1%
  739.                \or ####1####2%
  740.                \or ####1####2####3%
  741.                \or ####1####2####3####4%
  742.                \or ####1####2####3####4####5%
  743.                \or ####1####2####3####4####5####6%
  744.                \or ####1####2####3####4####5####6####7%
  745.                \or ####1####2####3####4####5####6####7####8%
  746.                \or ####1####2####3####4####5####6####7####8####9%
  747.                \fi
  748.             }%
  749.          \fi
  750.       \fi
  751.    \fi
  752.    \expandafter\@startdef\@paramdef{#1}%
  753. }%
  754. %
  755. %% [[[end of BibTeX-specific stuff]]]
  756. %
  757. %
  758. % Names of references (arguments given in the \cite and \nocite
  759. % commands) and file names (arguments given in the \bibliography and
  760. % \bibliographystyle commands) are recorded in \jobname.aux, called the
  761. % \@auxfile in these macros.  Here's how they get read in.
  762. %
  763. \def\@readauxfile{%
  764.    \if@auxfiledone \else % remember: \@auxfiledonetrue if \noauxfile is defined
  765.       \global\@auxfiledonetrue
  766.       \@testfileexistence{aux}%
  767.       \if@fileexists
  768.          \begingroup
  769.             % Because we might be in horizontal mode when \@readauxfile
  770.             % is called (if it's in response to a \cite or \nocite), we
  771.             % want to ignore all the would-be spaces at the ends of
  772.             % lines in the aux file.  Fortunately, it's highly unlikely
  773.             % an end-of-line might actually be desired.
  774.             % And because we don't change the category code of anything
  775.             % but @, primitives like \gdef can't be used to define labels
  776.             % in the aux file.  The solution adopted by btxmac.tex is to
  777.             % write `\@citedef{LABEL}{DEFINITION}' to the aux file, and
  778.             % use \csname on LABEL.
  779.             \endlinechar = -1
  780.             \catcode`@ = 11
  781.             \input \jobname.aux
  782.          \endgroup
  783.       \else
  784.          \message{\@undefinedmessage}%
  785.          \global\@citewarningfalse
  786.       \fi
  787.       \immediate\openout\@auxfile = \jobname.aux
  788.    \fi
  789. }%
  790. %
  791. % The \@readauxfile macro does all that work the first time it's called.
  792. % Since it's called once for every \cite, \nocite, \bibliography, and
  793. % \bibliographystyle command that the user issues, we need to remember
  794. % whether the work's been done.  It's considered done if we're not to do
  795. % it---that is, if \noauxfile is defined.
  796. %
  797. \newif\if@auxfiledone
  798. \ifx\noauxfile\@undefined \else \@auxfiledonetrue\fi
  799. %
  800. % It's conceivable you'd want to change how other characters are read;
  801. % to do that, change their category code before doing \input btxmac.
  802. %
  803. %
  804. % After reading the .aux file, \@readauxfile opens it for writing.
  805. % The \@writeaux macro does the actual writing (as long as
  806. % \noauxfile is undefined).
  807. %
  808. \@innernewwrite\@auxfile
  809. \def\@writeaux#1{\ifx\noauxfile\@undefined \write\@auxfile{#1}\fi}%
  810. %
  811. %
  812. % A macro package that uses btxmac.tex might define
  813. % \@undefinedmessage (before doing an \input btxmac).
  814. %
  815. \ifx\@undefinedmessage\@undefined
  816.    \def\@undefinedmessage{No .aux file; I won't give you warnings about
  817.                           undefined citations.}%
  818. \fi
  819. %
  820. % Even if citations are undefined, we want to complain only if
  821. % \@citewarningtrue.  The default is to set \@citewarningtrue unless
  822. % \noauxfile is defined.  Again, a macro package that uses
  823. % btxmac.tex might want to redefine this.
  824. %
  825. \@innernewif\if@citewarning
  826. \ifx\noauxfile\@undefined \@citewarningtrue\fi
  827. %
  828. %
  829. % Finally, before leaving we restore @'s old category code.
  830. %
  831. \catcode`@ = \@oldatcatcode
  832.